from appserver import db_store

class Blacklist(db_store.Model):
    __tablename__="blacklist"
    __bind_key__="main"

    id=db_store.Column(db_store.Integer,primary_key=True)
    tablename=db_store.Column(db_store.String(64),nullable=False)    # MySQL表名最长为64
    hide_id=db_store.Column(db_store.String(64),nullable=False)    # 隐藏数据行的id
    id_type=db_store.Column(db_store.String(16),nullable=False)    # 数据行id的类型: string-字符串 int-整型

    def __repr__(self):
        return "<Blacklist %s+%s>" %(self.tablename,self.hide_id)

    def save(self):
        try:
            db_store.session.add(self)
            db_store.session.commit()
            return 0
        except Exception as e:
            print("table blacklist write error:\n-----------------------\n%s\n-------------------------" %e)
            db_store.session.rollback()
            return -1

    def delete(self):
        try:
            db_store.session.delete(self)
            db_store.session.commit()
            return 0
        except Exception as e:
            print("table blacklist delete error:\n--------------------\n%s\n------------------------" %e)
            db_store.session.rollback()
            return -1
